home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / gnulib2.c < prev    next >
C/C++ Source or Header  |  1992-04-26  |  30KB  |  1,644 lines

  1. /* WARNING: compile this in 32 bit int mode even for short library */
  2. #include <string.h>
  3. #ifndef _COMPILER_H
  4. #include <compiler.h>
  5. #endif
  6.  
  7. #ifdef __DEF_ALL__    /* this def'ed when making on the ST */
  8.  
  9. #define L_adddi3
  10. #define L_subdi3
  11. #define L_muldi3
  12. #define L_divdi3
  13. #define L_moddi3
  14. #define L_udivdi3
  15. #define L_umoddi3
  16. #define L_negdi2
  17. #define L_anddi3
  18. #define L_iordi3
  19. #define L_xordi3
  20. #define L_lshrdi3
  21. #define L_lshldi3
  22. #define L_ashldi3
  23. #define L_ashrdi3
  24. #define L_one_cmpldi2
  25. #define L_bdiv
  26. #define L_cmpdi2
  27. #define L_ucmpdi2
  28. #define L_fixunsdfdi
  29. #define L_fixdfdi
  30. #define L_floatdidf
  31.  
  32. /* gcc-2.0 stuff */
  33. #if 0    /* NOTE: these are now covered, and should not be generated here */
  34. #define L_lshrsi3
  35. #define L_lshlsi3
  36. #define L_ashrsi3
  37. #define L_ashlsi3
  38. #define L_eqdf2
  39. #define L_nedf2
  40. #define L_gtdf2
  41. #define L_gedf2
  42. #define L_ltdf2
  43. #define L_ledf2
  44. #define L_fixsfsi
  45. #define L_floatsisf
  46. #define L_eqsf2
  47. #define L_nesf2
  48. #define L_gtsf2
  49. #define L_gesf2
  50. #define L_ltsf2
  51. #define L_lesf2
  52. #endif
  53. #define L_fxussfsi
  54.  
  55. #endif /* __DEF_ALL__ */
  56.  
  57. /* More subroutines needed by GCC output code on some machines.  */
  58. /* Compile this one with gcc.  */
  59.  
  60. #if 0
  61. #include "config.h"    /* dont drag this in, just define relevant
  62.                stuff from xm/tm-atari.h & xm/tm-m68k.h here */
  63. #else
  64.  
  65. /* #defines that need visibility everywhere.  */
  66. #define FALSE 0
  67. #define TRUE 1
  68.  
  69. /* This describes the machine the compiler is hosted on.  */
  70. #define HOST_BITS_PER_CHAR 8
  71. #define HOST_BITS_PER_SHORT 16
  72. #define HOST_BITS_PER_INT 32
  73. #define HOST_BITS_PER_LONG 32
  74.  
  75. #ifdef __GNUC__
  76. #ifndef minix
  77. #define alloca __builtin_alloca
  78. #else
  79.      void *alloca(unsigned long);
  80. #endif
  81. #endif
  82.  
  83. /* Define this if most significant bit is lowest numbered
  84.    in instructions that operate on numbered bit-fields.
  85.    This is true for 68020 insns such as bfins and bfexts.
  86.    We make it true always by avoiding using the single-bit insns
  87.    except in special cases with constant bit numbers.  */
  88. #define BITS_BIG_ENDIAN
  89.  
  90. /* Define this if most significant byte of a word is the lowest numbered.  */
  91. /* That is true on the 68000.  */
  92. #define BYTES_BIG_ENDIAN
  93.  
  94. /* Define this if most significant word of a multiword number is numbered.  */
  95. /* For 68000 we can decide arbitrarily
  96.    since there are no machine instructions for them.  */
  97. /* #define WORDS_BIG_ENDIAN */
  98.  
  99. /* number of bits in an addressible storage unit */
  100. #define BITS_PER_UNIT 8
  101.  
  102. /* Width in bits of a "word", which is the contents of a machine register.
  103.    Note that this is not necessarily the width of data type `int';
  104.    if using 16-bit ints on a 68000, this would still be 32.
  105.    But on a machine with 16-bit registers, this would be 16.  */
  106. #define BITS_PER_WORD 32
  107.  
  108. /* Width of a word, in units (bytes).  */
  109. #define UNITS_PER_WORD 4
  110.  
  111. /* Width in bits of a pointer.
  112.    See also the macro `Pmode' defined below.  */
  113. #define POINTER_SIZE 32
  114.  
  115. /* Allocation boundary (in *bits*) for storing pointers in memory.  */
  116. #define POINTER_BOUNDARY 16
  117.  
  118. /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
  119. #define PARM_BOUNDARY (TARGET_SHORT ? 16 : 32)
  120.  
  121. /* Boundary (in *bits*) on which stack pointer should be aligned.  */
  122. #define STACK_BOUNDARY 16
  123.  
  124. /* Allocation boundary (in *bits*) for the code of a function.  */
  125. #define FUNCTION_BOUNDARY 16
  126.  
  127. /* Alignment of field after `int : 0' in a structure.  */
  128. #define EMPTY_FIELD_BOUNDARY 16
  129.  
  130. /* No data type wants to be aligned rounder than this.  */
  131. #define BIGGEST_ALIGNMENT 16
  132.  
  133. /* Define this if move instructions will actually fail to work
  134.    when given unaligned data.  */
  135. #define STRICT_ALIGNMENT
  136.  
  137. /* Define number of bits in most basic integer type.
  138.    (If undefined, default is BITS_PER_WORD).  */
  139. #ifdef __MSHORT__
  140. #define INT_TYPE_SIZE 16
  141. #else
  142. #define INT_TYPE_SIZE 32
  143. #endif
  144.  
  145. #endif
  146.  
  147. #ifndef minix
  148. #include <stddef.h>
  149. #else
  150.      typedef unsigned long size_t;
  151. #include "lib.h"
  152. #endif
  153.  
  154. #ifndef SItype
  155. #define SItype long int
  156. #endif
  157.  
  158. /* long long ints are pairs of long ints in the order determined by
  159.    WORDS_BIG_ENDIAN.  */
  160.  
  161. #ifdef WORDS_BIG_ENDIAN
  162.   struct longlong {long high, low;};
  163. #else
  164.   struct longlong {long low, high;};
  165. #endif
  166.  
  167. /* We need this union to unpack/pack longlongs, since we don't have
  168.    any arithmetic yet.  Incoming long long parameters are stored
  169.    into the `ll' field, and the unpacked result is read from the struct
  170.    longlong.  */
  171.  
  172. typedef union
  173. {
  174.   struct longlong s;
  175.   long long ll;
  176.   SItype i[2];
  177.   unsigned SItype ui[2];
  178. } long_long;
  179.  
  180. /* Internally, long long ints are strings of unsigned shorts in the
  181.    order determined by BYTES_BIG_ENDIAN.  */
  182.  
  183. #define B 0x10000
  184. #define low16 (B - 1)
  185.  
  186. #ifdef BYTES_BIG_ENDIAN
  187.  
  188. /* Note that HIGH and LOW do not describe the order
  189.    of words in a long long.  They describe the order of words
  190.    in vectors ordered according to the byte order.  */
  191.  
  192. #define HIGH 0
  193. #define LOW 1
  194.  
  195. #define big_end(n)    0 
  196. #define little_end(n)    ((n) - 1)
  197. #define next_msd(i)    ((i) - 1)
  198. #define next_lsd(i)    ((i) + 1)
  199. #define is_not_msd(i,n)    ((i) >= 0)
  200. #define is_not_lsd(i,n)    ((i) < (n))
  201.  
  202. #else
  203.  
  204. #define LOW 0
  205. #define HIGH 1
  206.  
  207. #define big_end(n)    ((n) - 1)
  208. #define little_end(n)    0 
  209. #define next_msd(i)    ((i) + 1)
  210. #define next_lsd(i)    ((i) - 1)
  211. #define is_not_msd(i,n)    ((i) < (n))
  212. #define is_not_lsd(i,n)    ((i) >= 0)
  213.  
  214. #endif
  215.  
  216. /* These algorithms are all straight out of Knuth, vol. 2, sec. 4.3.1. */
  217.  
  218. __EXTERN long long __adddi3 __PROTO((long long u, long long v));
  219. static int badd __PROTO((unsigned short *a, unsigned short *b, unsigned short *c, size_t n));
  220. __EXTERN long long __anddi3 __PROTO((long long u, long long v));
  221. __EXTERN long long __iordi3 __PROTO((long long u, long long v));
  222. __EXTERN long long __xordi3 __PROTO((long long u, long long v));
  223. __EXTERN long long __one_cmpldi2 __PROTO((long long u));
  224. __EXTERN long long __lshldi3 __PROTO((long long u, long int b1));
  225. __EXTERN long long __lshrdi3 __PROTO((long long u, long int b1));
  226. __EXTERN long long __ashldi3 __PROTO((long long u, long int b1));
  227. __EXTERN long long __ashrdi3 __PROTO((long long u, long int b1));
  228. __EXTERN long long __subdi3 __PROTO((long long u, long long v));
  229. static int bsub __PROTO((unsigned short *a, unsigned short *b, unsigned short *c, size_t n));
  230. __EXTERN long long __muldi3 __PROTO((long long u, long long v));
  231. static void bmul __PROTO((unsigned short *a, unsigned short *b, unsigned short *c, size_t m, size_t n));
  232. __EXTERN long long __divdi3 __PROTO((long long u, long long v));
  233. __EXTERN long long __moddi3 __PROTO((long long u, long long v));
  234. __EXTERN long long __udivdi3 __PROTO((long long u, long long v));
  235. __EXTERN long long __umoddi3 __PROTO((long long u, long long v));
  236. __EXTERN long long __negdi2 __PROTO((long long u));
  237. static int bneg __PROTO((unsigned short *a, unsigned short *b, size_t n));
  238. __EXTERN void __bdiv __PROTO((unsigned short *a, unsigned short *b, unsigned short *q, unsigned short *r, size_t m, size_t n));
  239. static int bshift __PROTO((unsigned short *u, int k, unsigned short *w, unsigned int carry_in, int n));
  240. __EXTERN SItype __cmpdi2 __PROTO((long long a, long long b));
  241. __EXTERN SItype __ucmpdi2 __PROTO((long long a, long long b));
  242. __EXTERN long long __fixunsdfdi __PROTO((double a));
  243. __EXTERN long long __fixdfdi __PROTO((double a));
  244. __EXTERN double __floatdidf __PROTO((long long u));
  245. __EXTERN int __builtin_saveregs __PROTO((void));
  246. __EXTERN unsigned SItype __fixunssfsi __PROTO((float a));
  247.  
  248. #ifdef L_adddi3
  249. long long 
  250. __adddi3 (u, v)
  251.      long long u, v;
  252. {
  253.   long a[2], b[2], c[2];
  254.   long_long w;
  255.   long_long uu, vv;
  256.  
  257.   uu.ll = u;
  258.   vv.ll = v;
  259.  
  260.   a[HIGH] = uu.s.high;
  261.   a[LOW] = uu.s.low;
  262.   b[HIGH] = vv.s.high;
  263.   b[LOW] = vv.s.low;
  264.  
  265.   badd ((unsigned short *)a, (unsigned short *)b, (unsigned short *)c, sizeof c);
  266.  
  267.   w.s.high = c[HIGH];
  268.   w.s.low = c[LOW];
  269.   return w.ll;
  270. }
  271.  
  272. static int 
  273. badd (a, b, c, n)
  274.      unsigned short *a, *b, *c;
  275.      size_t n;
  276. {
  277.   unsigned long acc;
  278.   int i;
  279.  
  280.   n /= sizeof *c;
  281.  
  282.   acc = 0;
  283.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  284.     {
  285.       /* Widen before adding to avoid loss of high bits.  */
  286.       acc += (unsigned long) a[i] + b[i];
  287.       c[i] = acc & low16;
  288.       acc = acc >> 16;
  289.     }
  290.   return acc;
  291. }
  292. #endif
  293.  
  294. #ifdef L_anddi3
  295. long long 
  296. __anddi3 (u, v)
  297.      long long u, v;
  298. {
  299.   long_long w;
  300.   long_long uu, vv;
  301.  
  302.   uu.ll = u;
  303.   vv.ll = v;
  304.  
  305.   w.s.high = uu.s.high & vv.s.high;
  306.   w.s.low = uu.s.low & vv.s.low;
  307.  
  308.   return w.ll;
  309. }
  310. #endif
  311.  
  312. #ifdef L_iordi3
  313. long long 
  314. __iordi3 (u, v)
  315.      long long u, v;
  316. {
  317.   long_long w;
  318.   long_long uu, vv;
  319.  
  320.   uu.ll = u;
  321.   vv.ll = v;
  322.  
  323.   w.s.high = uu.s.high | vv.s.high;
  324.   w.s.low = uu.s.low | vv.s.low;
  325.  
  326.   return w.ll;
  327. }
  328. #endif
  329.  
  330. #ifdef L_xordi3
  331. long long 
  332. __xordi3 (u, v)
  333.      long long u, v;
  334. {
  335.   long_long w;
  336.   long_long uu, vv;
  337.  
  338.   uu.ll = u;
  339.   vv.ll = v;
  340.  
  341.   w.s.high = uu.s.high ^ vv.s.high;
  342.   w.s.low = uu.s.low ^ vv.s.low;
  343.  
  344.   return w.ll;
  345. }
  346. #endif
  347.  
  348. #ifdef L_one_cmpldi2
  349. long long
  350. __one_cmpldi2 (u)
  351.      long long u;
  352. {
  353.   long_long w;
  354.   long_long uu;
  355.  
  356.   uu.ll = u;
  357.  
  358.   w.s.high = ~uu.s.high;
  359.   w.s.low = ~uu.s.low;
  360.  
  361.   return w.ll;
  362. }
  363. #endif
  364.  
  365. #ifdef L_lshldi3
  366. long long
  367. __lshldi3 (u, b1)
  368.      long long u;
  369.      long int b1;
  370. {
  371.   long_long w;
  372.   unsigned long carries;
  373.   int bm;
  374.   long_long uu;
  375.   int b = b1;
  376.   
  377.   if (b == 0)
  378.     return u;
  379.  
  380.   uu.ll = u;
  381.  
  382.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  383.   if (bm <= 0)
  384.     {
  385.       w.s.low = 0;
  386.       w.s.high = (unsigned long)uu.s.low << -bm;
  387.     }
  388.   else
  389.     {
  390.       carries = (unsigned long)uu.s.low >> bm;
  391.       w.s.low = (unsigned long)uu.s.low << b;
  392.       w.s.high = ((unsigned long)uu.s.high << b) | carries;
  393.     }
  394.  
  395.   return w.ll;
  396. }
  397. #endif
  398.  
  399. #ifdef L_lshrdi3
  400. long long
  401. __lshrdi3 (u, b1)
  402.      long long u;
  403.      long int b1;
  404. {
  405.   long_long w;
  406.   unsigned long carries;
  407.   int bm;
  408.   long_long uu;
  409.   int b = b1;
  410.   
  411.   if (b == 0)
  412.     return u;
  413.  
  414.   uu.ll = u;
  415.  
  416.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  417.   if (bm <= 0)
  418.     {
  419.       w.s.high = 0;
  420.       w.s.low = (unsigned long)uu.s.high >> -bm;
  421.     }
  422.   else
  423.     {
  424.       carries = (unsigned long)uu.s.high << bm;
  425.       w.s.high = (unsigned long)uu.s.high >> b;
  426.       w.s.low = ((unsigned long)uu.s.low >> b) | carries;
  427.     }
  428.  
  429.   return w.ll;
  430. }
  431. #endif
  432.  
  433. #ifdef L_ashldi3
  434. long long
  435. __ashldi3 (u, b1)
  436.      long long u;
  437.      long int b1;
  438. {
  439.   long_long w;
  440.   unsigned long carries;
  441.   int bm;
  442.   long_long uu;
  443.   int b = b1;
  444.   
  445.   if (b == 0)
  446.     return u;
  447.  
  448.   uu.ll = u;
  449.  
  450.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  451.   if (bm <= 0)
  452.     {
  453.       w.s.low = 0;
  454.       w.s.high = (unsigned long)uu.s.low << -bm;
  455.     }
  456.   else
  457.     {
  458.       carries = (unsigned long)uu.s.low >> bm;
  459.       w.s.low = (unsigned long)uu.s.low << b;
  460.       w.s.high = ((unsigned long)uu.s.high << b) | carries;
  461.     }
  462.  
  463.   return w.ll;
  464. }
  465. #endif
  466.  
  467. #ifdef L_ashrdi3
  468. long long
  469. __ashrdi3 (u, b1)
  470.      long long u;
  471.      long int b1;
  472. {
  473.   long_long w;
  474.   unsigned long carries;
  475.   int bm;
  476.   long_long uu;
  477.   int b = b1;
  478.   
  479.   if (b == 0)
  480.     return u;
  481.  
  482.   uu.ll = u;
  483.  
  484.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  485.   if (bm <= 0)
  486.     {
  487.       w.s.high = uu.s.high >> 31; /* just to make w.s.high 1..1 or 0..0 */
  488.       w.s.low = uu.s.high >> -bm;
  489.     }
  490.   else
  491.     {
  492.       carries = (unsigned long)uu.s.high << bm;
  493.       w.s.high = uu.s.high >> b;
  494.       w.s.low = ((unsigned long)uu.s.low >> b) | carries;
  495.     }
  496.  
  497.   return w.ll;
  498. }
  499. #endif
  500.  
  501. #ifdef L_subdi3
  502. long long 
  503. __subdi3 (u, v)
  504.      long long u, v;
  505. {
  506.   long a[2], b[2], c[2];
  507.   long_long w;
  508.   long_long uu, vv;
  509.  
  510.   uu.ll = u;
  511.   vv.ll = v;
  512.  
  513.   a[HIGH] = uu.s.high;
  514.   a[LOW] = uu.s.low;
  515.   b[HIGH] = vv.s.high;
  516.   b[LOW] = vv.s.low;
  517.  
  518.   bsub ((unsigned short *)a, (unsigned short *)b, (unsigned short *)c, sizeof c);
  519.  
  520.   w.s.high = c[HIGH];
  521.   w.s.low = c[LOW];
  522.   return w.ll;
  523. }
  524.  
  525. static int 
  526. bsub (a, b, c, n)
  527.      unsigned short *a, *b, *c;
  528.      size_t n;
  529. {
  530.   signed long acc;
  531.   int i;
  532.  
  533.   n /= sizeof *c;
  534.  
  535.   acc = 0;
  536.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  537.     {
  538.       /* Widen before subtracting to avoid loss of high bits.  */
  539.       acc += (long) a[i] - b[i];
  540.       c[i] = acc & low16;
  541.       acc = acc >> 16;
  542.     }
  543.   return acc;
  544. }
  545. #endif
  546.  
  547. #ifdef L_muldi3
  548. long long 
  549. __muldi3 (u, v)
  550.      long long u, v;
  551. {
  552.   long a[2], b[2], c[2][2];
  553.   long_long w;
  554.   long_long uu, vv;
  555.  
  556.   uu.ll = u;
  557.   vv.ll = v;
  558.  
  559.   a[HIGH] = uu.s.high;
  560.   a[LOW] = uu.s.low;
  561.   b[HIGH] = vv.s.high;
  562.   b[LOW] = vv.s.low;
  563.  
  564.   bmul ((unsigned short *)a, (unsigned short *)b, (unsigned short *)c, sizeof a, sizeof b);
  565.  
  566.   w.s.high = c[LOW][HIGH];
  567.   w.s.low = c[LOW][LOW];
  568.   return w.ll;
  569. }
  570.  
  571. static void 
  572. bmul (a, b, c, m, n)
  573.     unsigned short *a, *b, *c;
  574.     size_t m, n;
  575. {
  576.   int i, j;
  577.   unsigned long acc;
  578.  
  579.   (void)bzero (c, m + n);
  580.  
  581.   m /= sizeof *a;
  582.   n /= sizeof *b;
  583.  
  584.   for (j = little_end (n); is_not_msd (j, n); j = next_msd (j))
  585.     {
  586.       unsigned short *c1 = c + j + little_end (2);
  587.       acc = 0;
  588.       for (i = little_end (m); is_not_msd (i, m); i = next_msd (i))
  589.     {
  590.       /* Widen before arithmetic to avoid loss of high bits.  */
  591.       acc += (unsigned long) a[i] * b[j] + c1[i];
  592.       c1[i] = acc & low16;
  593.       acc = acc >> 16;
  594.     }
  595.       c1[i] = acc;
  596.     }
  597. }
  598. #endif
  599.  
  600. #ifdef L_divdi3
  601. long long
  602. __divdi3 (u, v)
  603.      long long u, v;
  604. {
  605.   if (u < 0)
  606.     if (v < 0)
  607.       return (unsigned long long) -u / (unsigned long long) -v;
  608.     else
  609.       return - ((unsigned long long) -u / (unsigned long long) v);
  610.   else
  611.     if (v < 0)
  612.       return - ((unsigned long long) u / (unsigned long long) -v);
  613.     else
  614.       return (unsigned long long) u / (unsigned long long) v;
  615. }
  616. #endif
  617.  
  618. #ifdef L_moddi3
  619. long long
  620. __moddi3 (u, v)
  621.      long long u, v;
  622. {
  623.   if (u < 0)
  624.     if (v < 0)
  625.       return - ((unsigned long long) -u % (unsigned long long) -v);
  626.     else
  627.       return - ((unsigned long long) -u % (unsigned long long) v);
  628.   else
  629.     if (v < 0)
  630.       return (unsigned long long) u % (unsigned long long) -v;
  631.     else
  632.       return (unsigned long long) u % (unsigned long long) v;
  633. }
  634. #endif
  635.  
  636. #ifdef L_udivdi3
  637. long long 
  638. __udivdi3 (u, v)
  639.      long long u, v;
  640. {
  641.   unsigned long a[2][2], b[2], q[2], r[2];
  642.   long_long w;
  643.   long_long uu, vv;
  644.  
  645.   uu.ll = u;
  646.   vv.ll = v;
  647.  
  648.   a[HIGH][HIGH] = 0;
  649.   a[HIGH][LOW] = 0;
  650.   a[LOW][HIGH] = uu.s.high;
  651.   a[LOW][LOW] = uu.s.low;
  652.   b[HIGH] = vv.s.high;
  653.   b[LOW] = vv.s.low;
  654.  
  655.   __bdiv ((unsigned short *)a, (unsigned short *)b, (unsigned short *)q,
  656.       (unsigned short *)r, sizeof a, sizeof b);
  657.  
  658.   w.s.high = q[HIGH];
  659.   w.s.low = q[LOW];
  660.   return w.ll;
  661. }
  662. #endif
  663.  
  664. #ifdef L_umoddi3
  665. long long 
  666. __umoddi3 (u, v)
  667.      long long u, v;
  668. {
  669.   unsigned long a[2][2], b[2], q[2], r[2];
  670.   long_long w;
  671.   long_long uu, vv;
  672.  
  673.   uu.ll = u;
  674.   vv.ll = v;
  675.  
  676.   a[HIGH][HIGH] = 0;
  677.   a[HIGH][LOW] = 0;
  678.   a[LOW][HIGH] = uu.s.high;
  679.   a[LOW][LOW] = uu.s.low;
  680.   b[HIGH] = vv.s.high;
  681.   b[LOW] = vv.s.low;
  682.  
  683.   __bdiv ((unsigned short *)a, (unsigned short *)b, (unsigned short *)q,
  684.       (unsigned short *)r, sizeof a, sizeof b);
  685.  
  686.   w.s.high = r[HIGH];
  687.   w.s.low = r[LOW];
  688.   return w.ll;
  689. }
  690. #endif
  691.  
  692. #ifdef L_negdi2
  693. long long 
  694. __negdi2 (u)
  695.      long long u;
  696. {
  697.   unsigned long a[2], b[2];
  698.   long_long w;
  699.   long_long uu;
  700.  
  701.   uu.ll = u;
  702.  
  703.   a[HIGH] = uu.s.high;
  704.   a[LOW] = uu.s.low;
  705.  
  706.   bneg ((unsigned short *)a, (unsigned short *)b, sizeof b);
  707.  
  708.   w.s.high = b[HIGH];
  709.   w.s.low = b[LOW];
  710.   return w.ll;
  711. }
  712.  
  713. static int
  714. bneg (a, b, n)
  715.      unsigned short *a, *b;
  716.      size_t n;
  717. {
  718.   signed long acc;
  719.   int i;
  720.  
  721.   n /= sizeof (short);
  722.  
  723.   acc = 0;
  724.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  725.     {
  726.       acc -= a[i];
  727.       b[i] = acc & low16;
  728.       acc = acc >> 16;
  729.     }
  730.   return acc;
  731. }
  732. #endif
  733.  
  734. /* Divide a by b, producing quotient q and remainder r.
  735.  
  736.        sizeof a is m
  737.        sizeof b is n
  738.        sizeof q is m - n
  739.        sizeof r is n
  740.  
  741.    The quotient must fit in m - n bytes, i.e., the most significant
  742.    n digits of a must be less than b, and m must be greater than n.  */
  743.  
  744. /* The name of this used to be __div_internal,
  745.    but that is too long for SYSV.  */
  746.  
  747. #ifdef L_bdiv
  748. void 
  749. __bdiv (a, b, q, r, m, n)
  750.      unsigned short *a, *b, *q, *r;
  751.      size_t m, n;
  752. {
  753.   void abort(void);
  754.   unsigned long qhat, rhat;
  755.   unsigned long acc;
  756.   unsigned short *u = (unsigned short *) alloca (m);
  757.   unsigned short *v = (unsigned short *) alloca (n);
  758.   unsigned short *u0, *u1, *u2;
  759.   unsigned short *v0;
  760.   int d, qn;
  761.   int i, j;
  762.  
  763.   m /= sizeof *a;
  764.   n /= sizeof *b;
  765.   qn = m - n;
  766.  
  767.   /* Remove leading zero digits from divisor, and the same number of
  768.      digits (which must be zero) from dividend.  */
  769.  
  770.   while (b[big_end (n)] == 0)
  771.     {
  772.       r[big_end (n)] = 0;
  773.  
  774.       a += little_end (2);
  775.       b += little_end (2);
  776.       r += little_end (2);
  777.       m--;
  778.       n--;
  779.  
  780.       /* Check for zero divisor.  */
  781.       if (n == 0)
  782.     abort ();
  783.     }
  784.       
  785.   /* If divisor is a single digit, do short division.  */
  786.  
  787.   if (n == 1)
  788.     {
  789.       acc = a[big_end (m)];
  790.       a += little_end (2);
  791.       for (j = big_end (qn); is_not_lsd (j, qn); j = next_lsd (j))
  792.     {
  793.       acc = (acc << 16) | a[j];
  794.       q[j] = acc / *b;
  795.       acc = acc % *b;
  796.     }
  797.       *r = acc;
  798.       return;
  799.     }
  800.  
  801.   /* No such luck, must do long division. Shift divisor and dividend
  802.      left until the high bit of the divisor is 1.  */
  803.  
  804.   for (d = 0; d < 16; d++)
  805.     if (b[big_end (n)] & (1 << (16 - 1 - d)))
  806.       break;
  807.  
  808.   bshift (a, d, u, 0, m);
  809.   bshift (b, d, v, 0, n);
  810.  
  811.   /* Get pointers to the high dividend and divisor digits.  */
  812.  
  813.   u0 = u + big_end (m) - big_end (qn);
  814.   u1 = next_lsd (u0);
  815.   u2 = next_lsd (u1);
  816.   u += little_end (2);
  817.  
  818.   v0 = v + big_end (n);
  819.  
  820.   /* Main loop: find a quotient digit, multiply it by the divisor,
  821.      and subtract that from the dividend, shifted over the right amount. */
  822.  
  823.   for (j = big_end (qn); is_not_lsd (j, qn); j = next_lsd (j))
  824.     {
  825.       /* Quotient digit initial guess: high 2 dividend digits over high
  826.      divisor digit.  */
  827.  
  828.       if (u0[j] == *v0)
  829.     {
  830.       qhat = B - 1;
  831.       rhat = (unsigned long) *v0 + u1[j];
  832.     }
  833.       else
  834.     {
  835.       unsigned long numerator = ((unsigned long) u0[j] << 16) | u1[j];
  836.       qhat = numerator / *v0;
  837.       rhat = numerator % *v0;
  838.     }
  839.  
  840.       /* Now get the quotient right for high 3 dividend digits over
  841.      high 2 divisor digits.  */
  842.  
  843.       while (rhat < B && qhat * *next_lsd (v0) > ((rhat << 16) | u2[j]))
  844.     {
  845.       qhat -= 1;
  846.       rhat += *v0;
  847.     }
  848.         
  849.       /* Multiply quotient by divisor, subtract from dividend.  */
  850.  
  851.       acc = 0;
  852.       for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  853.     {
  854.       acc += (unsigned long) (u + j)[i] - v[i] * qhat;
  855.       (u + j)[i] = acc & low16;
  856.       if (acc < B)
  857.         acc = 0;
  858.       else
  859.         acc = (acc >> 16) | -B;
  860.     }
  861.  
  862.       q[j] = qhat;
  863.  
  864.       /* Quotient may have been too high by 1.  If dividend went negative,
  865.      decrement the quotient by 1 and add the divisor back.  */
  866.  
  867.       if ((signed long) (acc + u0[j]) < 0)
  868.     {
  869.       q[j] -= 1;
  870.       acc = 0;
  871.       for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  872.         {
  873.           acc += (unsigned long) (u + j)[i] + v[i];
  874.           (u + j)[i] = acc & low16;
  875.           acc = acc >> 16;
  876.         }
  877.     }
  878.     }
  879.  
  880.   /* Now the remainder is what's left of the dividend, shifted right
  881.      by the amount of the normalizing left shift at the top.  */
  882.  
  883.   r[big_end (n)] = bshift (u + 1 + little_end (j - 1),
  884.                16 - d,
  885.                r + little_end (2),
  886.                u[little_end (m - 1)] >> d,
  887.                n - 1);
  888. }
  889.  
  890. /* Left shift U by K giving W; fill the introduced low-order bits with
  891.    CARRY_IN.  Length of U and W is N.  Return carry out.  K must be
  892.    in 0 .. 16.  */
  893.  
  894. static int
  895. bshift (u, k, w, carry_in, n)
  896.      unsigned short *u, *w;
  897.      unsigned int carry_in;
  898.      int k, n;
  899. {
  900.   unsigned long acc;
  901.   int i;
  902.  
  903.   if (k == 0)
  904.     {
  905.       bcopy (u, w, n * sizeof *u);
  906.       return 0;
  907.     }
  908.  
  909.   acc = carry_in;
  910.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  911.     {
  912.       acc |= (unsigned long) u[i] << k;
  913.       w[i] = acc & low16;
  914.       acc = acc >> 16;
  915.     }
  916.   return acc;
  917. }
  918. #endif
  919.  
  920. #ifdef L_cmpdi2
  921. SItype
  922. __cmpdi2 (a, b)
  923.      long long a, b;
  924. {
  925.   long_long au, bu;
  926.  
  927.   au.ll = a, bu.ll = b;
  928.  
  929.   if (au.s.high < bu.s.high)
  930.     return 0;
  931.   else if (au.s.high > bu.s.high)
  932.     return 2;
  933.   if ((unsigned) au.s.low < (unsigned) bu.s.low)
  934.     return 0;
  935.   else if ((unsigned) au.s.low > (unsigned) bu.s.low)
  936.     return 2;
  937.   return 1;
  938. }
  939. #endif
  940.  
  941. #ifdef L_ucmpdi2
  942. SItype
  943. __ucmpdi2 (a, b)
  944.      long long a, b;
  945. {
  946.   long_long au, bu;
  947.  
  948.   au.ll = a, bu.ll = b;
  949.  
  950.   if ((unsigned) au.s.high < (unsigned) bu.s.high)
  951.     return 0;
  952.   else if ((unsigned) au.s.high > (unsigned) bu.s.high)
  953.     return 2;
  954.   if ((unsigned) au.s.low < (unsigned) bu.s.low)
  955.     return 0;
  956.   else if ((unsigned) au.s.low > (unsigned) bu.s.low)
  957.     return 2;
  958.   return 1;
  959. }
  960. #endif
  961.  
  962. #ifdef L_fixunsdfdi
  963. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  964.  
  965. long long
  966. __fixunsdfdi (a)
  967.      double a;
  968. {
  969.   double b;
  970.   unsigned long long v;
  971.  
  972.   if (a < 0)
  973.     return 0;
  974.  
  975.   /* Compute high word of result, as a flonum.  */
  976.   b = (a / HIGH_WORD_COEFF);
  977.   /* Convert that to fixed (but not to long long!),
  978.      and shift it into the high word.  */
  979.   v = (unsigned long int) b;
  980.   v <<= BITS_PER_WORD;
  981.   /* Remove high part from the double, leaving the low part as flonum.  */
  982.   a -= (double)v;
  983.   /* Convert that to fixed (but not to long long!) and add it in.
  984.      Sometimes A comes out negative.  This is significant, since
  985.      A has more bits than a long int does.  */
  986.   if (a < 0)
  987.     v -= (unsigned long int) (- a);
  988.   else
  989.     v += (unsigned long int) a;
  990.   return v;
  991. }
  992. #endif
  993.  
  994. #ifdef L_fixdfdi
  995. long long
  996. __fixdfdi (a)
  997.      double a;
  998. {
  999.   long long __fixunsdfdi (double a);
  1000.  
  1001.   if (a < 0)
  1002.     return - __fixunsdfdi (-a);
  1003.   return __fixunsdfdi (a);
  1004. }
  1005. #endif
  1006.  
  1007. #ifdef L_floatdidf
  1008. #define HIGH_HALFWORD_COEFF (((long long) 1) << (BITS_PER_WORD / 2))
  1009. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  1010.  
  1011. double
  1012. __floatdidf (u)
  1013.      long long u;
  1014. {
  1015.   double d;
  1016.   int negate = 0;
  1017.  
  1018.   if (u < 0)  /* was : if (d < 0)     */
  1019.     u = -u, negate = 1;
  1020.  
  1021.   d = (unsigned int) (u >> BITS_PER_WORD);
  1022.   d *= HIGH_HALFWORD_COEFF;
  1023.   d *= HIGH_HALFWORD_COEFF;
  1024.   d += (unsigned int) (u & (HIGH_WORD_COEFF - 1));
  1025.  
  1026.   return (negate ? -d : d);
  1027. }
  1028. #endif
  1029.  
  1030. #ifdef L_varargs
  1031. #ifdef sparc
  1032.     asm (".global ___builtin_saveregs");
  1033.     asm ("___builtin_saveregs:");
  1034.     asm ("st %i0,[%fp+68]");
  1035.     asm ("st %i1,[%fp+72]");
  1036.     asm ("st %i2,[%fp+76]");
  1037.     asm ("st %i3,[%fp+80]");
  1038.     asm ("st %i4,[%fp+84]");
  1039.     asm ("retl");
  1040.     asm ("st %i5,[%fp+88]");
  1041. #else /* not sparc */
  1042. #if defined(MIPSEL) | defined(R3000) | defined(R2000) | defined(mips)
  1043.  
  1044.   asm ("    .ent __builtin_saveregs");
  1045.   asm ("    .globl __builtin_saveregs");
  1046.   asm ("__builtin_saveregs:");
  1047.   asm ("    sw    $4,0($30)");
  1048.   asm ("    sw    $5,4($30)");
  1049.   asm ("    sw    $6,8($30)");
  1050.   asm ("    sw    $7,12($30)");
  1051.   asm ("    j    $31");
  1052.   asm ("    .end __builtin_saveregs");
  1053. #else /* not mips */
  1054. __builtin_saveregs ()
  1055. {
  1056.   abort ();
  1057. }
  1058. #endif /* not mips */
  1059. #endif /* not sparc */
  1060. #endif
  1061.  
  1062. /* stuff for gcc-2.0, note that you cannot compile the corresponding
  1063.    C code from libgcc1.c for these functions with gcc-2.0!
  1064.    This stuff should eventually be hand optimized as we have done
  1065.    with the other stuff,
  1066.  */
  1067.  
  1068. #if 0    /* these were the decls used to compile the asm below */
  1069.  
  1070. #ifndef SItype
  1071. #define SItype long int
  1072. #endif
  1073.  
  1074. #ifndef FLOAT_VALUE_TYPE  
  1075. #define FLOAT_VALUE_TYPE long int
  1076. #endif
  1077.  
  1078. #ifndef INTIFY
  1079. #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  1080. #endif
  1081.  
  1082. #ifndef FLOATIFY
  1083. #define FLOATIFY(INTVAL)  ((INTVAL).f)
  1084. #endif
  1085.  
  1086. #ifndef FLOAT_ARG_TYPE
  1087. #define FLOAT_ARG_TYPE union flt_or_int
  1088. #endif
  1089.  
  1090. union flt_or_value { FLOAT_VALUE_TYPE i; float f; };
  1091.  
  1092. union flt_or_int { long int i; float f; };
  1093. #endif
  1094.  
  1095. #if 0        /* NOTE: all these come from elsewhere now */
  1096. #ifdef L_lshrsi3
  1097. #if 0
  1098. SItype
  1099. __lshrsi3 (a, b)
  1100.      unsigned SItype a, b;
  1101. {
  1102.   return a >> b;
  1103. }
  1104. #endif
  1105.  
  1106. asm("    .text
  1107.     .even
  1108. .globl ___lshrsi3
  1109. ___lshrsi3:
  1110.     movel sp@(4),d0
  1111.     movel sp@(8),d1
  1112.     lsrl d1,d0
  1113.     rts
  1114. ");
  1115. #endif
  1116.  
  1117. #ifdef L_lshlsi3
  1118. #if 0
  1119. SItype
  1120. __lshlsi3 (a, b)
  1121.      unsigned SItype a, b;
  1122. {
  1123.   return a << b;
  1124. }
  1125. #endif
  1126.  
  1127. asm("   .text
  1128.     .even
  1129. .globl ___lshlsi3
  1130. ___lshlsi3:
  1131.     movel sp@(4),d0
  1132.     movel sp@(8),d1
  1133.     lsll d1,d0
  1134.     rts
  1135. ");
  1136. #endif
  1137.  
  1138. #ifdef L_ashrsi3
  1139. #if 0
  1140. SItype
  1141. __ashrsi3 (a, b)
  1142.      SItype a, b;
  1143. {
  1144.   return a >> b;
  1145. }
  1146. #endif
  1147.  
  1148. asm("   .text
  1149.     .even
  1150. .globl ___ashrsi3
  1151. ___ashrsi3:
  1152.     movel sp@(4),d0
  1153.     movel sp@(8),d1
  1154.     asrl d1,d0
  1155.     rts
  1156. ");
  1157. #endif
  1158.  
  1159. #ifdef L_ashlsi3
  1160. #if 0
  1161. SItype
  1162. __ashlsi3 (a, b)
  1163.      SItype a, b;
  1164. {
  1165.   return a << b;
  1166. }
  1167. #endif
  1168.  
  1169. asm("    .text
  1170.     .even
  1171. .globl ___ashlsi3
  1172. ___ashlsi3:
  1173.     movel sp@(4),d0
  1174.     movel sp@(8),d1
  1175.     asll d1,d0
  1176.     rts
  1177. ");
  1178. #endif
  1179.  
  1180. #ifdef L_eqdf2
  1181. #if 0
  1182. SItype
  1183. __eqdf2 (a, b)
  1184.      double a, b;
  1185. {
  1186.   /* Value == 0 iff a == b.  */
  1187.   return !(a == b);
  1188. }
  1189. #endif
  1190.  
  1191. asm("    .text
  1192.     .even
  1193. .globl ___eqdf2
  1194. ___eqdf2:
  1195.     moveml #0x3000,sp@-
  1196.     movel sp@(12),d1
  1197.     movel sp@(16),d2
  1198.     movel sp@(24),sp@-
  1199.     movel sp@(24),sp@-
  1200.     movel d2,sp@-
  1201.     movel d1,sp@-
  1202.     jbsr ___cmpdf2
  1203.     addw #16,sp
  1204.     tstl d0
  1205.     sne d0
  1206.     moveq #1,d3
  1207.     andl d3,d0
  1208.     moveml sp@+,#0xc
  1209.     rts
  1210. ");
  1211. #endif
  1212.  
  1213. #ifdef L_nedf2
  1214. #if 0
  1215. SItype
  1216. __nedf2 (a, b)
  1217.      double a, b;
  1218. {
  1219.   /* Value != 0 iff a != b.  */
  1220.   return a != b;
  1221. }
  1222. #endif
  1223.  
  1224. asm("    .text
  1225.     .even
  1226. .globl ___nedf2
  1227. ___nedf2:
  1228.     moveml #0x3000,sp@-
  1229.     movel sp@(12),d1
  1230.     movel sp@(16),d2
  1231.     movel sp@(24),sp@-
  1232.     movel sp@(24),sp@-
  1233.     movel d2,sp@-
  1234.     movel d1,sp@-
  1235.     jbsr ___cmpdf2
  1236.     addw #16,sp
  1237.     tstl d0
  1238.     sne d0
  1239.     moveq #1,d3
  1240.     andl d3,d0
  1241.     moveml sp@+,#0xc
  1242.     rts
  1243. ");
  1244. #endif
  1245.  
  1246. #ifdef L_gtdf2
  1247. #if 0
  1248. SItype
  1249. __gtdf2 (a, b)
  1250.      double a, b;
  1251. {
  1252.   /* Value > 0 iff a > b.  */
  1253.   return a > b;
  1254. }
  1255. #endif
  1256.  
  1257. asm("    .text
  1258.     .even
  1259. .globl ___gtdf2
  1260. ___gtdf2:
  1261.     moveml #0x3000,sp@-
  1262.     movel sp@(12),d1
  1263.     movel sp@(16),d2
  1264.     movel sp@(24),sp@-
  1265.     movel sp@(24),sp@-
  1266.     movel d2,sp@-
  1267.     movel d1,sp@-
  1268.     jbsr ___cmpdf2
  1269.     addw #16,sp
  1270.     tstl d0
  1271.     sgt d0
  1272.     moveq #1,d3
  1273.     andl d3,d0
  1274.     moveml sp@+,#0xc
  1275.     rts
  1276. ");
  1277. #endif
  1278.  
  1279. #ifdef L_gedf2
  1280. #if 0
  1281. SItype
  1282. __gedf2 (a, b)
  1283.      double a, b;
  1284. {
  1285.   /* Value >= 0 iff a >= b.  */
  1286.   return (a >= b) - 1;
  1287. }
  1288. #endif
  1289.  
  1290. asm("    .text
  1291.     .even
  1292. .globl ___gedf2
  1293. ___gedf2:
  1294.     moveml #0x3000,sp@-
  1295.     movel sp@(12),d1
  1296.     movel sp@(16),d2
  1297.     movel sp@(24),sp@-
  1298.     movel sp@(24),sp@-
  1299.     movel d2,sp@-
  1300.     movel d1,sp@-
  1301.     jbsr ___cmpdf2
  1302.     addw #16,sp
  1303.     tstl d0
  1304.     sge d0
  1305.     moveq #1,d3
  1306.     andl d3,d0
  1307.     subql #1,d0
  1308.     moveml sp@+,#0xc
  1309.     rts
  1310. ");
  1311. #endif
  1312.  
  1313. #ifdef L_ltdf2
  1314. #if 0
  1315. SItype
  1316. __ltdf2 (a, b)
  1317.      double a, b;
  1318. {
  1319.   /* Value < 0 iff a < b.  */
  1320.   return -(a < b);
  1321. }
  1322. #endif
  1323.  
  1324. asm("    .text
  1325.     .even
  1326. .globl ___ltdf2
  1327. ___ltdf2:
  1328.     moveml #0x3000,sp@-
  1329.     movel sp@(12),d1
  1330.     movel sp@(16),d2
  1331.     movel sp@(24),sp@-
  1332.     movel sp@(24),sp@-
  1333.     movel d2,sp@-
  1334.     movel d1,sp@-
  1335.     jbsr ___cmpdf2
  1336.     addw #16,sp
  1337.     tstl d0
  1338.     slt d0
  1339.     moveq #1,d3
  1340.     andl d3,d0
  1341.     negl d0
  1342.     moveml sp@+,#0xc
  1343.     rts
  1344. ");
  1345. #endif
  1346.  
  1347. #ifdef L_ledf2
  1348. #if 0
  1349. SItype
  1350. __ledf2 (a, b)
  1351.      double a, b;
  1352. {
  1353.   /* Value <= 0 iff a <= b.  */
  1354.   return 1 - (a <= b);
  1355. }
  1356. #endif
  1357.  
  1358. asm("    .text
  1359.     .even
  1360. .globl ___ledf2
  1361. ___ledf2:
  1362.     movel d2,sp@-
  1363.     movel sp@(8),d0
  1364.     movel sp@(12),d1
  1365.     moveq #1,d2
  1366.     movel sp@(20),sp@-
  1367.     movel sp@(20),sp@-
  1368.     movel d1,sp@-
  1369.     movel d0,sp@-
  1370.     jbsr ___cmpdf2
  1371.     addw #16,sp
  1372.     tstl d0
  1373.     jgt L11
  1374.     moveq #0,d2
  1375. L11:
  1376.     movel d2,d0
  1377.     movel sp@+,d2
  1378.     rts
  1379. ");
  1380. #endif
  1381.  
  1382. #ifdef L_fixsfsi
  1383. #if 0
  1384. SItype
  1385. __fixsfsi (a)
  1386.      FLOAT_ARG_TYPE a;
  1387. {
  1388.   union flt_or_value intify;
  1389. #define perform_fixsfsi(a) return (SItype) a
  1390.   perform_fixsfsi (FLOATIFY (a));
  1391. }
  1392. #endif
  1393.  
  1394. asm("    .text
  1395.     .even
  1396. .globl ___fixsfsi
  1397. ___fixsfsi:
  1398.     movel sp@(4),sp@-
  1399.     jbsr ___extendsfdf2
  1400.     addqw #4,sp
  1401.     movel d1,sp@-
  1402.     movel d0,sp@-
  1403.     jbsr ___fixdfsi
  1404.     addqw #8,sp
  1405.     rts
  1406. ");
  1407. #endif
  1408.  
  1409. #ifdef L_floatsisf
  1410. #if 0
  1411. FLOAT_VALUE_TYPE
  1412. __floatsisf (a)
  1413.      SItype a;
  1414. {
  1415.   union flt_or_value intify;
  1416. #define perform_floatsisf(a)  return INTIFY ((float) a)
  1417.   perform_floatsisf (a);
  1418. }
  1419. #endif
  1420.  
  1421. asm("    .text
  1422.     .even
  1423. .globl ___floatsisf
  1424. ___floatsisf:
  1425.     movel sp@(4),sp@-
  1426.     jbsr ___floatsidf
  1427.     addqw #4,sp
  1428.     movel d1,sp@-
  1429.     movel d0,sp@-
  1430.     jbsr ___truncdfsf2
  1431.     addqw #8,sp
  1432.     rts
  1433. ");
  1434. #endif
  1435.  
  1436. #ifdef L_eqsf2
  1437. #if 0
  1438. SItype
  1439. __eqsf2 (a, b)
  1440.      FLOAT_ARG_TYPE a, b;
  1441. {
  1442.   union flt_or_int intify;
  1443.   /* Value == 0 iff a == b.  */
  1444. #define perform_eqsf2(a, b) return !(a == b)
  1445.   perform_eqsf2 (FLOATIFY (a), FLOATIFY (b));
  1446. }
  1447. #endif
  1448.  
  1449. asm("    .text
  1450.     .even
  1451. .globl ___eqsf2
  1452. ___eqsf2:
  1453.     movel d2,sp@-
  1454.     movel sp@(8),d1
  1455.     movel sp@(12),sp@-
  1456.     movel d1,sp@-
  1457.     jbsr ___cmpsf2
  1458.     addqw #8,sp
  1459.     tstl d0
  1460.     sne d0
  1461.     moveq #1,d2
  1462.     andl d2,d0
  1463.     movel sp@+,d2
  1464.     rts
  1465. ");
  1466. #endif
  1467.  
  1468. #ifdef L_nesf2
  1469. #if 0
  1470. SItype
  1471. __nesf2 (a, b)
  1472.      FLOAT_ARG_TYPE a, b;
  1473. {
  1474.   union flt_or_int intify;
  1475.   /* Value != 0 iff a != b.  */
  1476. #define perform_nesf2(a, b) return a != b
  1477.   perform_nesf2 (FLOATIFY (a), FLOATIFY (b));
  1478. }
  1479. #endif
  1480.  
  1481. asm("    .text
  1482.     .even
  1483. .globl ___nesf2
  1484. ___nesf2:
  1485.     movel d2,sp@-
  1486.     movel sp@(8),d1
  1487.     movel sp@(12),sp@-
  1488.     movel d1,sp@-
  1489.     jbsr ___cmpsf2
  1490.     addqw #8,sp
  1491.     tstl d0
  1492.     sne d0
  1493.     moveq #1,d2
  1494.     andl d2,d0
  1495.     movel sp@+,d2
  1496.     rts
  1497. ");
  1498. #endif
  1499.  
  1500. #ifdef L_gtsf2
  1501. #if 0
  1502. SItype
  1503. __gtsf2 (a, b)
  1504.      FLOAT_ARG_TYPE a, b;
  1505. {
  1506.   union flt_or_int intify;
  1507.   /* Value > 0 iff a > b.  */
  1508. #define perform_gtsf2(a, b) return a > b
  1509.   perform_gtsf2 (FLOATIFY (a), FLOATIFY (b));
  1510. }
  1511. #endif
  1512.  
  1513. asm("    .text
  1514.     .even
  1515. .globl ___gtsf2
  1516. ___gtsf2:
  1517.     movel d2,sp@-
  1518.     movel sp@(8),d1
  1519.     movel sp@(12),sp@-
  1520.     movel d1,sp@-
  1521.     jbsr ___cmpsf2
  1522.     addqw #8,sp
  1523.     tstl d0
  1524.     sgt d0
  1525.     moveq #1,d2
  1526.     andl d2,d0
  1527.     movel sp@+,d2
  1528.     rts
  1529. ");
  1530. #endif
  1531.  
  1532. #ifdef L_gesf2
  1533. #if 0
  1534. SItype
  1535. __gesf2 (a, b)
  1536.      FLOAT_ARG_TYPE a, b;
  1537. {
  1538.   union flt_or_int intify;
  1539.   /* Value >= 0 iff a >= b.  */
  1540. #define perform_gesf2(a, b) return (a >= b) - 1
  1541.   perform_gesf2 (FLOATIFY (a), FLOATIFY (b));
  1542. }
  1543. #endif
  1544.  
  1545. asm("    .text
  1546.     .even
  1547. .globl ___gesf2
  1548. ___gesf2:
  1549.     movel d2,sp@-
  1550.     movel sp@(8),d1
  1551.     movel sp@(12),sp@-
  1552.     movel d1,sp@-
  1553.     jbsr ___cmpsf2
  1554.     addqw #8,sp
  1555.     tstl d0
  1556.     sge d0
  1557.     moveq #1,d2
  1558.     andl d2,d0
  1559.     subql #1,d0
  1560.     movel sp@+,d2
  1561.     rts
  1562. ");
  1563. #endif
  1564.  
  1565. #ifdef L_ltsf2
  1566. #if 0
  1567. SItype
  1568. __ltsf2 (a, b)
  1569.      FLOAT_ARG_TYPE a, b;
  1570. {
  1571.   union flt_or_int intify;
  1572.   /* Value < 0 iff a < b.  */
  1573. #define perform_ltsf2(a, b) return -(a < b)
  1574.   perform_ltsf2 (FLOATIFY (a), FLOATIFY (b));
  1575. }
  1576. #endif
  1577.  
  1578. asm("    .text
  1579.     .even
  1580. .globl ___ltsf2
  1581. ___ltsf2:
  1582.     movel d2,sp@-
  1583.     movel sp@(8),d1
  1584.     movel sp@(12),sp@-
  1585.     movel d1,sp@-
  1586.     jbsr ___cmpsf2
  1587.     addqw #8,sp
  1588.     tstl d0
  1589.     slt d0
  1590.     moveq #1,d2
  1591.     andl d2,d0
  1592.     negl d0
  1593.     movel sp@+,d2
  1594.     rts
  1595. ");
  1596. #endif
  1597.  
  1598. #ifdef L_lesf2
  1599. #if 0
  1600. SItype
  1601. __lesf2 (a, b)
  1602.      FLOAT_ARG_TYPE a, b;
  1603. {
  1604.   union flt_or_int intify;
  1605.   /* Value <= 0 iff a <= b.  */
  1606. #define perform_lesf2(a, b) return 1 - (a <= b); /* note bug fix from libgcc1.c */
  1607.   perform_lesf2 (FLOATIFY (a), FLOATIFY (b));
  1608. }
  1609. #endif
  1610.  
  1611. asm("    .text
  1612.     .even
  1613. .globl ___lesf2
  1614. ___lesf2:
  1615.     movel d2,sp@-
  1616.     movel sp@(8),d0
  1617.     moveq #1,d2
  1618.     movel sp@(12),sp@-
  1619.     movel d0,sp@-
  1620.     jbsr ___cmpsf2
  1621.     addqw #8,sp
  1622.     tstl d0
  1623.     jgt L20
  1624.     moveq #0,d2
  1625. L20:
  1626.     movel d2,d0
  1627.     movel sp@+,d2
  1628.     rts
  1629. ");
  1630. #endif
  1631. #endif    /* # if 0 to ensure that the above functions are not compiled */
  1632.  
  1633.  
  1634. #ifdef L_fxussfsi
  1635. #include <limits.h>
  1636. unsigned SItype
  1637. __fixunssfsi (float a)
  1638. {
  1639.   if (a >= - (float) LONG_MIN)
  1640.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1641.   return (SItype) a;
  1642. }
  1643. #endif
  1644.